﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BuySoftwareOnline.Domain.Abstract;

namespace BuySoftwareOnline.Domain.Concrete
{
    public class EmployeerRepository : IEmployeerRepository
    {
        private BuySoftwareOnlineDataContext context;

        public EmployeerRepository()
        {
            context = new BuySoftwareOnlineDataContext();
        }

        public IQueryable<Employeer> Employeers
        {
            get { return context.Employeers; }
        }

        public void SaveEmployeer(Employeer employeer)
        {
            if (employeer.EmployeerID == 0)
            {
                context.Employeers.InsertOnSubmit(employeer);
            }
            else
            {
                context.Employeers.Attach(employeer);
                context.Refresh(System.Data.Linq.RefreshMode.KeepCurrentValues, employeer);
            }
            context.SubmitChanges();
        }

        public void DeleteEmployeer(Employeer employeer)
        {
            context.Employeers.DeleteOnSubmit(employeer);
            context.SubmitChanges();
        }
    }
}
